home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / wc.pas < prev    next >
Pascal/Delphi Source File  |  1984-12-03  |  2KB  |  65 lines

  1.  
  2.  program wc;
  3. {$I arglist.pin}
  4.     const
  5.        blank = ' ';
  6.        tab = ^I;
  7.        newline = ^J;
  8.        cr = ^M;
  9.        teof = ^Z;
  10.  
  11.     var
  12.        infile : file;
  13.        filename : string[20];
  14.        inbuf : array[1..512] of char;
  15.        words,lines,chars : integer;
  16.        iptr : integer;
  17.        ch : char;
  18.        inword : boolean;
  19.  
  20.     begin
  21.        words := 0;
  22.        lines := 0;
  23.        chars := 0;
  24.        inword := false;
  25.        if argc <> 1 then begin
  26.        write('input - ');
  27.        readln(filename);
  28.        assign(infile,filename);
  29.        end
  30.        else assign(infile,argv(1));
  31.        reset(infile);
  32.        repeat
  33.        {$I-}
  34.           blockread(infile,inbuf,4);
  35.           {$I+}
  36.           if ioresult <> 0 then begin
  37.                 gotoxy(1,4);
  38.                 writeln(chars,' C  ',words,' W  ',lines,' L  ');
  39.                 halt;
  40.                 end;
  41.           iptr := 1;
  42.           while iptr <= 512 do begin
  43.              ch := inbuf[iptr];
  44.              chars := chars+1;
  45.              iptr := iptr+1;
  46.              if ch=teof then begin
  47.                 gotoxy(1,4);
  48.                 writeln(chars,' C  ',words,' W  ',lines,' L  ');
  49.                 halt;
  50.                 end;
  51.  
  52.              if (ch=cr) or (ch=tab) or (ch=blank) then inword :=
  53.                   false
  54.              else if (ch=newline) then begin
  55.                  inword := false;
  56.                  lines := lines+1;
  57.                  end
  58.              else if not inword then begin
  59.                 inword := true;
  60.                 words := words+1;
  61.                 end;
  62.              end;
  63.           until eof(infile);
  64.        end.
  65.